;> ModuleAB64

RELEASEVER * 1;1 for release version: no MANDEL or Roger
FP * 1;1 for ARM FP instruction set
OWNERRORS * 0 ;1 for error messages in module
CHECKCRUNCH * 1 ;1 for BASIC$Crunch check on -quit and LIBRARY, INSTALL etc.
LOOKUPHELP * 1 ;1 for lookup command help syntax in Global.Messages file.
STRONGARM * 1 ;1 for StrongARM-compatible

 GBLS CurrentDate
CurrentDate SETS "8th September 1998"
 GBLS ShortDate
ShortDate SETS "08 Sep 1998"
 GBLS Version
Version SETS "1.18"

;Remember to change the Date!

VARS * &8700 ;allocation of the data pointer itself

 GBLS Name
 [ FP=0
Name SETS "BASIC"
 |
Name SETS "BASIC64"
 ]
;> &.Hdr.System

;***********************************
;*** C h a n g e L i s t ***
;***********************************

;Date Name Description
;---- ---- -----------
;28-Apr-87 APT Added ticker event SWIs

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;SWI names are exported in three forms:
;1) with OS_ 'OS_DoThingToOtherThing' as N
;2) with XOS_ 'XOS_DoThingToOtherThing' as N + Auto_Error_SWI_bit
;3) as is 'DoThingToOtherThing' as N ;But not for long !!

;***************************************************
;*** Generate SWI labels assuming ^ type defs ***
;*** Also assumes the global variable SWIClass ***
;***************************************************
 GBLS SWIClass
 MACRO
 AddSWI $SWIName,$value
 [ "$value" = ""
$SWIClass._$SWIName # 1
 |
$SWIClass._$SWIName * $value
 ]
X$SWIClass._$SWIName * $SWIClass._$SWIName + Auto_Error_SWI_bit
 MEND

Auto_Error_SWI_bit * 1:SHL: 17

SWIClass SETS "OS"

 ^ 0 ;Base for Arthur SWIs
 AddSWI WriteC ;&00
 AddSWI WriteS ;&01
 AddSWI Write0 ;&02
 AddSWI NewLine ;&03
 AddSWI ReadC ;&04
 AddSWI CLI ;&05
 AddSWI Byte ;&06
 AddSWI Word ;&07
 AddSWI File ;&08
 AddSWI Args ;&09
 AddSWI BGet ;&0A
 AddSWI BPut ;&0B
 AddSWI GBPB ;&0C
 AddSWI Find ;&0D
 AddSWI ReadLine ;&0E
 AddSWI Control ;&0F
 AddSWI GetEnv ;&10
 AddSWI Exit ;&11
 AddSWI SetEnv ;&12
 AddSWI IntOn ;&13
 AddSWI IntOff ;&14
 AddSWI CallBack ;&15
 AddSWI EnterOS ;&16
 AddSWI BreakPt ;&17
 AddSWI BreakCtrl ;&18
 AddSWI UnusedSWI ;&19
 AddSWI UpdateMEMC ;&1A
 AddSWI SetCallBack ;&1B
 AddSWI Mouse ;&1C

 AddSWI Heap ;&1D ;Our new ones start here
 AddSWI Module ;&1E
 AddSWI Claim ;&1F ;PMF's vector handling
 AddSWI Release ;&20 ;routines
 AddSWI ReadUnsigned ;&21 ;Read an unsigned number
 AddSWI GenerateEvent ;&22
 AddSWI ReadVarVal ;&23 ;read variable value & type
 AddSWI SetVarVal ;&24 ;set variable value & type
 AddSWI GSInit ;&25
 AddSWI GSRead ;&26
 AddSWI GSTrans ;&27
 AddSWI BinaryToDecimal ;&28
 AddSWI FSControl ;&29
 AddSWI ChangeDynamicArea ;&2A
 AddSWI GenerateError ;&2B
 AddSWI ReadEscapeState ;&2C
 AddSWI EvaluateExpression ;&2D
 AddSWI SpriteOp ;&2E
 AddSWI ReadPalette ;&2F ;(was FontManager)
 AddSWI ServiceCall ;&30 ;was Claim_Release_FIQ
 AddSWI ReadVduVariables ;&31
 AddSWI ReadPoint ;&32
 AddSWI UpCall ;&33
 AddSWI CallAVector ;&34 ;was ReadCurrentError
 AddSWI ReadModeVariable ;&35
 AddSWI RemoveCursors ;&36
 AddSWI RestoreCursors ;&37
 AddSWI SWINumberToString ;&38
 AddSWI SWINumberFromString ;&39

 ^ &C0
 AddSWI ConvertStandardDateAndTime ;&C0
 AddSWI ConvertDateAndTime ;&C1

 AddSWI WriteI,&100

 AddSWI UserSWI,&200

;Allocation of Operating System SWI Chunks
 ^ 3
StringConvSWI # 1

 ^ 8 ;OS chunk allocation starts at &200
FileSwitchSWI # 1


;Allocation of System extension SWI Chunks

 ^ 0
EconetSWI # 1
NetFSSWI # 1
FontSWI # 1
WimpSWI # 1
TubeSWI # 1
Sound0SWI # 1
Sound1SWI # 1
Sound2SWI # 1
NetPrintSWI # 1
ADFSSWI # 1
ROMPoduleSWI # 1

;Allocation of Application SWI Chunks

 ^ 0
MailSWI # 1
NetMonitorSWI # 1
ConmputerConcepts # 1
MinervaSystemD # 1
ResourceNH01 # 1

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;CMOS RAM allocation

ReadCMOS * &A1 ;The OS_Byte call to read CMOS
WriteCMOS * &A2 ;The OS_Byte call to write CMOS

NetStnCMOS * &00 ;One byte
NetFSIDCMOS * &01 ;Two bytes
NetPSIDCMOS * &03 ;Two bytes
FileLangCMOS * &05 ;One byte
FrugalCMOS * &06 ;Two bytes
EDITCMOS * &08 ;One byte
TelcomCMOS * &09 ;One byte
MODETVCMOS * &0A ;One byte
StartCMOS * &0B ;One byte
KeyDelCMOS * &0C ;One byte
KeyRepCMOS * &0D ;One byte
PigCMOS * &0E ;One byte
PSITCMOS * &0F ;One byte
DBTBCMOS * &10 ;One byte
ANFSCMOS * &11 ;One byte

UserCMOS * &1E ;Sixteen bytes
FreeCMOS * &2E

MOSCMOS * &80 ;&80-&EF now being allocated ... sign here!
YearCMOS * &80 ;Two Bytes of year info (HEX)
MonthCMOS * &82 ;The last month we were in (HEX)
LeapCMOS * &83 ;The we've-had-the-29th-of-feb-this-year-already flag
TutuCMOS * &84 ;For nefarious porpoises
VduCMOS * &85
SyncBit * 1 ;Composite sync or not
ModeExtraBit * 2
FontCMOS * &86
NewADFSCMOS * &87 ;Three bytes (consult Nick)
;* &88
;* &89
CatalogCMOS * &8A ;Two bytes
ExamineCMOS * &8C ;Two bytes
TwinCMOS * &8E
ScreenSizeCMOS * &8F
RAMDiscCMOS * &90
SysHeapCMOS * &91
RMASizeCMOS * &92
SpriteSizeCMOS * &93
SoundCMOS * &94
ABE0 * &95 ;4 Bytes for the BASIC Editor.
ABE1 * &96 ;
ABE2 * &97 ;
ABE3 * &98 ;

PSNameCMOS * &DB ;5 bytes for 6 char name,one byte in NetPSId + 1
FSNameCMOS * &E0 ;15 bytes for 16 char name,one byte in NetFSId + 1
CheckSumCMOS * &EF ;One byte for CMOS RAM checksum

;Note that CMOS RAM ends at F0 where the clock starts

;> &.Hdr.ModHand

;***********************************
;*** C h a n g e L i s t ***
;***********************************

;Date Name Description
;---- ---- -----------
;23-Apr-87 APT Help-is-code flag moved into high byte

ModHandReason_Run * 0
ModHandReason_Load * 1
ModHandReason_Enter * 2
ModHandReason_ReInit * 3
ModHandReason_Delete * 4
ModHandReason_RMADesc * 5
ModHandReason_Claim * 6
ModHandReason_Free * 7
ModHandReason_Tidy * 8
ModHandReason_Clear * 9
ModHandReason_AddArea * 10
ModHandReason_CopyArea * 11
ModHandReason_GetNames * 12
ModHandReason_ExtendBlock * 13

;Real module offsets

 ^ 0
Module_Start # 4
Module_Init # 4
Module_Die # 4
Module_Service # 4
Module_Title # 4
Module_HelpStr # 4
Module_HC_Table # 4 ;help and command table.

;optional SWI handler offsets
Module_SWIChunk # 4
Module_SWIEntry # 4
Module_NameTable # 4
Module_NameCode # 4

;Magic number for RM load addr

Module_LoadAddr * &FFFFFA00 ;magic number from Stu/Bruce standard the two zeroes are ignored.

Module_SWIChunkSize * 2_1000000

Module_SWISystemBase * 1:SHL: 18
Module_SWIApplicationBase * 2:SHL: 18
Module_SWIUserBase * 3:SHL: 18


;flags for the information word:

FS_Command_Flag * 1:SHL: 31
Status_Keyword_Flag * 1:SHL: 30
Help_Is_Code_Flag * 1:SHL: 29

R0 RN 0
R1 RN 1
R2 RN 2
R3 RN 3
R4 RN 4
R5 RN 5
R6 RN 6
R7 RN 7
R8 RN 8
R9 RN 9
R10 RN 10
R11 RN 11
R12 RN 12
R13 RN 13
R14 RN 14
R15 RN 15
PC RN R15

;> &.Hdr.Services

;28-Apr-87  TMD   Added a few more service codes

;All the service call reason codes

Service_Serviced   * &00
Service_UKCommand  * &04
Service_Error      * &06 ;not quite the same: only for workspace tidying.
                         ;If you want to claim the error, sit on ErrorV
Service_UKByte     * &07 ;Unknown OSBYTEs go thru here
Service_UKWord     * &08 ;Unknown OSWORDs go thru here
Service_Help       * &09 ;Issued at the start of the *Help command:
                         ;claim if replacing the MOS *Help
Service_ReleaseFIQ * &0B
Service_ClaimFIQ   * &0C
Service_Memory     * &11
Service_StartUpFS  * &12
Service_Tube       * &FE ;Means "Tube changing state"
                         ;R2 = 0 for Tube not there
                         ;  <> 0 means Tube alive: may contain more info.

;Master OS ones:

Service_Post_Help  * &18 ;Passed round at the end of the *Help code
Service_Reset      * &27
Service_UKConfig   * &28
Service_UKStatus   * &29

 LEADR Module_LoadAddr

Module_BaseAddr * .

Basic_ModuleStart DCD MODULEMAIN-Module_BaseAddr
 DCD 0 ;Basic_Init
 DCD 0 ;Basic_Die
 DCD Basic_Services-Module_BaseAddr
 DCD Basic_Title-Module_BaseAddr
 DCD Basic_HelpStr-Module_BaseAddr
 DCD Basic_HC_Table-Module_BaseAddr
 DCD 0
 DCD 0
 DCD 0
 DCD 0
 [ LOOKUPHELP=1
 DCD message_filename-Module_BaseAddr
 |
 DCD 0
 ]

 MACRO
 Command $cmd
 DCB "$Name",0
 ALIGN
 DCD $cmd._Code -Module_BaseAddr
 [ LOOKUPHELP=1
 DCD &10FF0000
 |
 DCD &FF0000
 ]
 DCD $cmd._Syntax-Module_BaseAddr
 DCD $cmd._Help -Module_BaseAddr
 MEND
Basic_HC_Table
 Command Basic
 DCB 0
 ALIGN

 [ LOOKUPHELP=1
message_filename DCB    "Resources:$.Resources.BASIC.Messages",0
Basic_Help      DCB     "HBASBAS",0
Basic_Syntax    DCB     "SBASBAS",0
 |
Basic_Help
 DCB "$Name. is the ARM BBC BASIC interpreter."
 DCB 13
Basic_Syntax
 DCB "Syntax: *$Name. [-help|-chain|-load|-quit] <filename>",0
 ]
Basic_Title
 DCB "$Name.",0
Basic_HelpStr
 [ FP=0
 DCB "BBC BASIC V",9,"$Version"
 |
 DCB "BBC BASIC VI",9,"$Version"
 ]
 DCB " ($ShortDate)",0
 ALIGN

Basic_ServicesTable
 DCD 0
 DCD Basic_ServicesBody-Module_BaseAddr
 DCD Service_Memory
 DCD 0

;In r0 -> rest of command line
;r1 = number of parameters to *ab

Basic_Code MOV R2,R0
 MOV R0,#ModHandReason_Enter
 ADR R1,Basic_Title
 SWI XOS_Module

 DCD Basic_ServicesTable-Module_BaseAddr
Basic_Services
 MOV R0,R0
 CMP R1,#Service_Memory
 MOVNE PC,R14
Basic_ServicesBody
 ADR R12,Basic_ModuleStart
 CMP R2,R12 ;R2 contains the address of the currently active object
 ADRGEL R12,Basic_End
 CMPGE R12,R2
 MOVGE R1,#Service_Serviced ;claim service - it's in us
 MOV PC,R14

 LNK BASIC
